from Tkinter import *
from ttk import *

root = Tk()

class MyText(Text):
    def write(self, line):
        config(state=NORMAL)
        insert(END, line)
        config(state=DISABLED)

phpSessIdVar = StringVar()
fightEnemyTypeVar = StringVar()
fightFromLevelVar = IntVar()
fightToLevelVar = IntVar()
healIfLowerVar = IntVar()
assitAlliesVar = BooleanVar()
fightHordeVar = BooleanVar()
fightBossesVar = BooleanVar()
fightTournamentVar = BooleanVar()
getDaimyoBonusVar = BooleanVar()
getGoldenCloudVar = BooleanVar()
autoEquipWeaponsVar = BooleanVar()
sellUnusedWeaponsVar = BooleanVar()
sellKarmaWeaponsVar = BooleanVar()
sellFoodWeaponsVar = BooleanVar()
startButton = Button()
getPhpSessIdButton = Button()
textBox = 0
farming = False

#defining default values
fightFromLevelVar.set(-10)
fightToLevelVar.set(-3)
healIfLowerVar.set(70)
assitAlliesVar.set(True)
fightHordeVar.set(True)
fightBossesVar.set(False)
fightTournamentVar.set(True)
getDaimyoBonusVar.set(True)
getGoldenCloudVar.set(True)
autoEquipWeaponsVar.set(True)
sellUnusedWeaponsVar.set(True)
sellKarmaWeaponsVar.set(True)
sellFoodWeaponsVar.set(False)

def createWidgets(master):
    global getPhpSessIdButton
    
    #main frame
    master.title("Ninja Warz Bot")

    #first line
    topFrame = Frame(master)
    Label(topFrame, text="PHPSESSID:").pack(side=LEFT, pady=5, padx=5)
    Entry(topFrame, textvariable=phpSessIdVar).pack(side=LEFT,  pady=5, fill=X, expand=1)
    getPhpSessIdButton = Button(topFrame, text="Get from Chrome")
    getPhpSessIdButton.pack(side=LEFT, pady=5, padx=5)
    topFrame.pack(fill=X)


    #options frame
    options = Frame(master)

    #fight options (options sub frame)
    fightOptionsFrame = Labelframe(options, text='Fight Options')

    fightOptionsLine1 = Frame(fightOptionsFrame)
    Label(fightOptionsLine1, text="Enemy Type: ").pack(side=LEFT)        
    box = Combobox(fightOptionsLine1, textvariable=fightEnemyTypeVar, width=7, state='readonly')
    box['values'] = ('All', 'NPC', 'Players')
    box.current(0)
    box.pack(side=RIGHT)
    fightOptionsLine1.pack(anchor=W, padx=5, pady=5)

    fightOptionsLine2 = Frame(fightOptionsFrame)
    label = Label(fightOptionsLine2, text="From relative level: ").pack(side=LEFT)
    fromSpinbox = Spinbox(fightOptionsLine2, textvariable=fightFromLevelVar, from_=-10, to=10, width=4, state="readonly").pack(side=LEFT)
    fightOptionsLine2.pack(anchor=W, padx=5, pady=5)

    fightOptionsLine3 = Frame(fightOptionsFrame)
    label = Label(fightOptionsLine3, text="To relative level: ").pack(side=LEFT)
    fromSpinbox = Spinbox(fightOptionsLine3, textvariable=fightToLevelVar, from_=-10, to=10, width=4, state="readonly").pack(side=LEFT)
    fightOptionsLine3.pack(anchor=W, padx=5, pady=5)

    fightOptionsLine4 = Frame(fightOptionsFrame)
    label = Label(fightOptionsLine4, text="Heal if HP lower than: ").pack(side=LEFT)
    fromSpinbox = Spinbox(fightOptionsLine4, textvariable=healIfLowerVar, from_=5, to=100, increment=5, width=4, state="readonly").pack(side=LEFT)
    label = Label(fightOptionsLine4, text="%").pack(side=LEFT)
    fightOptionsLine4.pack(anchor=W, padx=5, pady=5)

    fightOptionsFrame.pack()

    #farm button
    startButton = Button(options, text="Start Fighting") #, command=callback)
    startButton.pack(anchor=N, fill=X, expand=1, padx=3, pady=3)

    #more options
    Checkbutton(options, text="Assit allies", variable=assitAlliesVar).pack(anchor=W, side=TOP)
    Checkbutton(options, text="Fight undead horde", variable=fightHordeVar).pack(anchor=W, side=TOP)
    Checkbutton(options, text="Fight bosses (beaten and new)", variable=fightBossesVar).pack(anchor=W, side=TOP)
    Checkbutton(options, text="Fight in tournament\nfor higher DPS weapon", variable=fightTournamentVar).pack(anchor=W, side=TOP)
    Checkbutton(options, text="Get Daimyo bonus", variable=getDaimyoBonusVar).pack(anchor=W, side=TOP)
    Checkbutton(options, text="Get golden cloulds", variable=getGoldenCloudVar).pack(anchor=W, side=TOP)
    Checkbutton(options, text="Equip best weapons on best ninjas", variable=autoEquipWeaponsVar).pack(anchor=W, side=TOP)
    Checkbutton(options, text="Sell unused weapons\nexcept karma and food weapons", variable=sellUnusedWeaponsVar).pack(anchor=W, side=TOP)
    Checkbutton(options, text="Sell karma weapons", variable=sellKarmaWeaponsVar).pack(anchor=W, side=TOP)
    Checkbutton(options, text="Sell food weapons", variable=sellFoodWeaponsVar).pack(anchor=W, side=TOP)

    options.pack(anchor=N, side=RIGHT, padx=3, pady=3)

    #Results frame
    fightFrame = Frame(master)

    textSBar = Scrollbar(fightFrame, orient=VERTICAL)
    textSBar.pack(side=RIGHT, fill=Y)
    textBox = MyText(fightFrame, wrap=WORD
                         , yscrollcommand=textSBar.set
                         , relief=SUNKEN
                         , takefocus=0
                         , borderwidth=1
                         , state=DISABLED
                         , cursor="arrow")                    
    textBox.pack(side=LEFT, fill=BOTH, expand=1)
    #Show the scrollbars and attach them"
    textSBar.config(command=textBox.yview)

    fightFrame.pack(side=LEFT, fill=BOTH, expand=1, padx=3, pady=3)

createWidgets(root)       
